////////////////////////////////////////////////////////////////////////////////
// This file is part of the Mist compiler.                                    //
//                                                                            //
// Copyright (C) 2008, 2009 The Mist project                                  //
//                                                                            //
// For a list of contributors, see the COMMITTERS file.                       //
//                                                                            //
// The Mist compiler is free software: you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by       //
// the Free Software Foundation, either version 3 of the License, or          //
// (at your option) any later version.                                        //
//                                                                            //
// The Mist compiler is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of             //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              //
// GNU General Public License for more details.                               //
//                                                                            //
// You should have received a copy of the GNU General Public License          //
// in the COPYING file. If not, see <http://www.gnu.org/licenses/>.           //
////////////////////////////////////////////////////////////////////////////////

///
/// \file
/// Contains the echo wrapper.
/// Makes it possible to output an AST in any compiler phase.
///

#ifndef ECHO_HPP
#define ECHO_HPP

////////////////////////////////////////////////////////////////////////////////
// Includes                                                                   //
////////////////////////////////////////////////////////////////////////////////

#include "common/outputproducer.hpp"
#include "common/ptr.hpp"
#include "common/types.hpp"

////////////////////////////////////////////////////////////////////////////////
// Forward Declarations                                                       //
////////////////////////////////////////////////////////////////////////////////

class Node;

////////////////////////////////////////////////////////////////////////////////
// echo Wrapper Class                                                         //
////////////////////////////////////////////////////////////////////////////////

/// Output decorator for a syntax tree node, which can produce an echo of the
/// original code. It will have lost its former formatting and comments, but the
/// output code will be equivalent.
///
/// It is meant to be a temporary object,
/// used like this: <tt>cout << echo(node);</tt>
///
class echo : public OutputProducer {
	public:
		
		enum Information {
			None                      = 0x0, ///< Print no extra information
			PartialCorrectnessOutline = 0x1, ///< Print only the partial correctness proof outline
			  TotalCorrectnessOutline = 0x2  ///< Print partial and total correctness proof outline
		};
		
		/// Build an echo producing wrapper object.
		///
		echo(
			wptr<Node> tree,  ///< the tree to produce an echo of
			uint info = None, ///< what additional information to output
			uint tabSize = 4  ///< the number of spaces to use for indentation
		);
		
		ostream& send_to_stream(ostream& out) const;
	
	private:
		
		wptr<Node> _tree;
		uint       _info;
		uint       _tabSize;
};

#endif // ECHO_HPP
